package com.eastfair.transport.service.impl;

//import com.baomidou.dynamic.datasource.annotation.DS;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.projectcore.enumeration.DataIsolationSystemSceneEnum;
import com.eastfair.transport.service.TransportServiceBookingService;
import com.eastfair.venuebooking.api.ServiceBookingFeign;
import com.eastfair.venueservice.dto.ServiceBookingDTO;
import com.eastfair.venueservice.dto.ServiceBookingQuery;
import com.eastfair.venueservice.vo.ServiceBookingVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* <p>
    * 业务实现类
    * 服务项
    * </p>
*
* @author linan
* @date 2022-08-01
*/
@Slf4j
@Service
//@DS("#thread.tenant")
public class TransportServiceBookingServiceImpl implements TransportServiceBookingService {

    @Resource
    private ServiceBookingFeign serviceBookingFeign;

    @Override
    public Boolean delServiceBooking(ServiceBookingDTO serviceBookingDTO) {
        R<Boolean> booleanR = serviceBookingFeign.delServiceBooking(serviceBookingDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public Boolean addServiceBookingOfTransport(List<ServiceBookingDTO> serviceBookingDTO) {
        for (ServiceBookingDTO bookingDTO : serviceBookingDTO) {
            bookingDTO.setDeclarationSystem(DataIsolationSystemSceneEnum.P_COMPOSITE_TRANSPORT.getCode());
            bookingDTO.setProviderSystem(DataIsolationSystemSceneEnum.P_COMPOSITE_VENUE.getCode());
        }
        R<Boolean> booleanR = serviceBookingFeign.addServiceBookingOfOrder(serviceBookingDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public List<ServiceBookingVO> queryServiceBookingListOfTransport(ServiceBookingQuery serviceBookingQuery) {
        R<List<ServiceBookingVO>> listR = serviceBookingFeign.queryServiceBookingListOfOrder(serviceBookingQuery);
        if(!listR.getIsSuccess()){
            throw BizException.wrap(listR.getCode(),listR.getMsg());
        }
        return listR.getData();
    }
}
